#include "calculator_dialog.h"

CalculatorDialog::CalculatorDialog(QWidget* parent):
	QDialog(parent)
{
	setupUi(this);

	line_edit_X->setValidator(new QDoubleValidator(this));

	line_edit_Y->setValidator(new QDoubleValidator(this));

	connect(line_edit_X, SIGNAL(textChanged(const QString&)),
		this, SLOT(enableCalculatorButton()));

	connect(line_edit_Y, SIGNAL(textChanged(const QString&)),
		this, SLOT(enableCalculatorButton()));

	connect(pushbutton_calcalator, SIGNAL(clicked()),
		this, SLOT(calculatorButtonClicked()));
}

void CalculatorDialog::enableCalculatorButton()
{
	bool b_X_ok;
	bool b_Y_ok;

	line_edit_X->text().toDouble(&b_X_ok);
	line_edit_Y->text().toDouble(&b_Y_ok);

	pushbutton_calcalator->setEnabled(b_X_ok && b_Y_ok);

	if (!pushbutton_calcalator->isEnabled())
	{
		line_edit_Z->setText("");
	}
}

void CalculatorDialog::calculatorButtonClicked()
{
	line_edit_Z->setText(QString::number(
		line_edit_X->text().toDouble() + 
		line_edit_Y->text().toDouble() 
	));
}


void CalculatorDialog::plus()
{
	line_edit_Z->setText(QString("dd"));
}